package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WxMater;
import com.ruoyi.system.service.IWxMaterService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * materController
 * 
 * @author ruoyi
 * @date 2021-07-31
 */
@Controller
@RequestMapping("/system/mater")
public class WxMaterController extends BaseController
{
    private String prefix = "system/mater";

    @Autowired
    private IWxMaterService wxMaterService;

    @RequiresPermissions("system:mater:view")
    @GetMapping()
    public String mater()
    {
        return prefix + "/mater";
    }

    /**
     * 查询mater列表
     */
    @RequiresPermissions("system:mater:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxMater wxMater)
    {
        startPage();
        List<WxMater> list = wxMaterService.selectWxMaterList(wxMater);
        return getDataTable(list);
    }

    /**
     * 导出mater列表
     */
    @RequiresPermissions("system:mater:export")
    @Log(title = "mater", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxMater wxMater)
    {
        List<WxMater> list = wxMaterService.selectWxMaterList(wxMater);
        ExcelUtil<WxMater> util = new ExcelUtil<WxMater>(WxMater.class);
        return util.exportExcel(list, "mater数据");
    }

    /**
     * 新增mater
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存mater
     */
    @RequiresPermissions("system:mater:add")
    @Log(title = "mater", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxMater wxMater)
    {
        return toAjax(wxMaterService.insertWxMater(wxMater));
    }

    /**
     * 修改mater
     */
    @GetMapping("/edit/{materId}")
    public String edit(@PathVariable("materId") Long materId, ModelMap mmap)
    {
        WxMater wxMater = wxMaterService.selectWxMaterById(materId);
        mmap.put("wxMater", wxMater);
        return prefix + "/edit";
    }

    /**
     * 修改保存mater
     */
    @RequiresPermissions("system:mater:edit")
    @Log(title = "mater", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxMater wxMater)
    {
        return toAjax(wxMaterService.updateWxMater(wxMater));
    }

    /**
     * 删除mater
     */
    @RequiresPermissions("system:mater:remove")
    @Log(title = "mater", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxMaterService.deleteWxMaterByIds(ids));
    }

    /**
     * 校验手机号码
     */
    @PostMapping("/checkPhoneUnique")
    @ResponseBody
    public String checkPhoneUnique(WxMater wxMater)
    {
        return wxMaterService.checkPhoneUnique(wxMater);
    }
}
